unit ibDic;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids, IBDataBase, IBCustomDataset, Db, StdCtrls;

type
  TibDicForm = class(TForm)
    DBGrid: TDBGrid;
    DataSrc: TDataSource;
    btnSelect: TButton;
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
    Fdb: TIBDatabase;
    FDS: TIBDataSet;
    Ftr: TIBTransaction;
    function GetSql: TStrings;
    procedure SetSql(const Value: TStrings);
  public
    { Public declarations }
    constructor Create(AOwner: TComponent; ADb: TIBDataBase);
    procedure Prepare;
    property Ds: TIBDataSet read FDS;
    property Sql: TStrings read GetSql write SetSql;
  end;

implementation

{$R *.DFM}

{ TibDicForm }

constructor TibDicForm.Create(AOwner: TComponent; ADb: TIBDataBase);
begin
  inherited Create(AOwner);
  FDb := ADb;
  FDS := TIBDataSet.Create(Self);
  FDS.Database := Fdb;
  Ftr := TIBTransaction.Create(Self);
  Ftr.DefaultDatabase := Fdb;
  FDS.Transaction := Ftr;
  DataSrc.DataSet := FDS;
end;

procedure TibDicForm.Prepare;
begin
  FDS.Open;
end;

function TibDicForm.GetSql: TStrings;
begin
  result := FDS.SelectSQL;
end;

procedure TibDicForm.SetSql(const Value: TStrings);
begin
  FDS.SelectSQL := Value;
end;

procedure TibDicForm.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then
    ModalResult := mrCancel;
end;

end.
